// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['kaitai-struct/KaitaiStream', './Varint', 'cp3-kaitai-zlib/InflateZlib'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'), require('./Varint'), require('cp3-kaitai-zlib/InflateZlib'));
  } else {
    root.Reftable = factory(root.KaitaiStream, root.Varint, root.InflateZlib);
  }
}(typeof self !== 'undefined' ? self : this, function (KaitaiStream, Varint, InflateZlib) {
/**
 * A reftable file is a portable binary file format customized for reference storage. References are sorted, enabling linear scans, binary search lookup, and range scans.
 * Storage in the file is organized into variable sized blocks. Prefix compression is used within a single block to reduce disk space. Block size and alignment are tunable by the writer.
 * @see {@link https://git-scm.com/docs/reftable/2.45.2|Source}
 * @see {@link https://about.gitlab.com/blog/2024/05/30/a-beginners-guide-to-the-git-reftable-format/|Source}
 */

var Reftable = (function() {
  function Reftable(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  Reftable.prototype._read = function() {
    this.firstRefBlock = new FirstRefBlock(this._io, this, this._root);
    if ( ((this.footer.totalSizeRef > this.footer.header.blockSize) && (this.footer.refIndexPosition != 0)) ) {
      this._raw_otherRefBlocks = this._io.readBytes((this.footer.totalSizeRef - this.footer.header.blockSize));
      var _io__raw_otherRefBlocks = new KaitaiStream(this._raw_otherRefBlocks);
      this.otherRefBlocks = new RefBlocks(_io__raw_otherRefBlocks, this, this._root);
    }
    if (this.footer.totalSizeRefIndex != 0) {
      this._raw_refIndexBlock = this._io.readBytes(this.footer.totalSizeRefIndex);
      var _io__raw_refIndexBlock = new KaitaiStream(this._raw_refIndexBlock);
      this.refIndexBlock = new IndexBlock(_io__raw_refIndexBlock, this, this._root);
    }
    if (this.footer.totalSizeObject != 0) {
      this._raw_objectBlocks = this._io.readBytes(this.footer.totalSizeObject);
      var _io__raw_objectBlocks = new KaitaiStream(this._raw_objectBlocks);
      this.objectBlocks = new ObjectBlocks(_io__raw_objectBlocks, this, this._root);
    }
    if (this.footer.totalSizeObjectIndex != 0) {
      this._raw_objectIndexBlock = this._io.readBytes(this.footer.totalSizeObjectIndex);
      var _io__raw_objectIndexBlock = new KaitaiStream(this._raw_objectIndexBlock);
      this.objectIndexBlock = new IndexBlock(_io__raw_objectIndexBlock, this, this._root);
    }
    if (this.footer.totalSizeLog != 0) {
      this._raw_logBlocks = this._io.readBytes(this.footer.totalSizeLog);
      var _io__raw_logBlocks = new KaitaiStream(this._raw_logBlocks);
      this.logBlocks = new LogBlocks(_io__raw_logBlocks, this, this._root);
    }
    if (this.footer.totalSizeLogIndex != 0) {
      this._raw_logIndexBlock = this._io.readBytes(this.footer.totalSizeLogIndex);
      var _io__raw_logIndexBlock = new KaitaiStream(this._raw_logIndexBlock);
      this.logIndexBlock = new IndexBlock(_io__raw_logIndexBlock, this, this._root);
    }
  }

  var RefRecordValueSymbolicReference = Reftable.RefRecordValueSymbolicReference = (function() {
    function RefRecordValueSymbolicReference(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecordValueSymbolicReference.prototype._read = function() {
      this.targetRefLen = new Varint(this._io, this, null);
      this.targetRef = KaitaiStream.bytesToStr(this._io.readBytes(this.targetRefLen.value), "ASCII");
    }

    return RefRecordValueSymbolicReference;
  })();

  var IndexRecord = Reftable.IndexRecord = (function() {
    function IndexRecord(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    IndexRecord.prototype._read = function() {
      this.refPrefixLength = new Varint(this._io, this, null);
      this.refSuffixInfo = new Varint(this._io, this, null);
      this.refSuffix = KaitaiStream.bytesToStr(this._io.readBytes(this.refSuffixLength), "ASCII");
      this.blockPosition = new Varint(this._io, this, null);
    }
    Object.defineProperty(IndexRecord.prototype, 'refSuffixLength', {
      get: function() {
        if (this._m_refSuffixLength !== undefined)
          return this._m_refSuffixLength;
        this._m_refSuffixLength = (this.refSuffixInfo.value >>> 3);
        return this._m_refSuffixLength;
      }
    });

    return IndexRecord;
  })();

  var ObjectRecords = Reftable.ObjectRecords = (function() {
    function ObjectRecords(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ObjectRecords.prototype._read = function() {
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.records.push(new ObjectRecord(this._io, this, this._root));
        i++;
      }
    }
    Object.defineProperty(ObjectRecords.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return ObjectRecords;
  })();

  var RefRecord = Reftable.RefRecord = (function() {
    function RefRecord(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecord.prototype._read = function() {
      this.refPrefixLength = new Varint(this._io, this, null);
      this.refSuffixInfo = new Varint(this._io, this, null);
      this.refSuffix = KaitaiStream.bytesToStr(this._io.readBytes(this.refSuffixLength), "ASCII");
      this.refUpdateIndexDelta = new Varint(this._io, this, null);
      switch (this.refValueType) {
      case 0:
        this.value = new RefRecordValueDeletion(this._io, this, this._root);
        break;
      case 1:
        this.value = new RefRecordValueOneObjectName(this._io, this, this._root);
        break;
      case 2:
        this.value = new RefRecordValueTwoObjectNames(this._io, this, this._root);
        break;
      case 3:
        this.value = new RefRecordValueSymbolicReference(this._io, this, this._root);
        break;
      }
    }
    Object.defineProperty(RefRecord.prototype, 'refSuffixLength', {
      get: function() {
        if (this._m_refSuffixLength !== undefined)
          return this._m_refSuffixLength;
        this._m_refSuffixLength = (this.refSuffixInfo.value >>> 3);
        return this._m_refSuffixLength;
      }
    });
    Object.defineProperty(RefRecord.prototype, 'refValueType', {
      get: function() {
        if (this._m_refValueType !== undefined)
          return this._m_refValueType;
        this._m_refValueType = (this.refSuffixInfo.value & 7);
        return this._m_refValueType;
      }
    });

    return RefRecord;
  })();

  var LogData = Reftable.LogData = (function() {
    function LogData(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    LogData.prototype._read = function() {
      this.oldId = this._io.readBytes(20);
      this.newId = this._io.readBytes(20);
      this.nameLength = new Varint(this._io, this, null);
      this.name = KaitaiStream.bytesToStr(this._io.readBytes(this.nameLength.value), "ASCII");
      this.emailLength = new Varint(this._io, this, null);
      this.email = KaitaiStream.bytesToStr(this._io.readBytes(this.emailLength.value), "ASCII");
      this.timeSeconds = new Varint(this._io, this, null);
      this.tzOffset = this._io.readS2be();
      this.messageLength = new Varint(this._io, this, null);
      this.message = KaitaiStream.bytesToStr(this._io.readBytes(this.messageLength.value), "ASCII");
    }

    return LogData;
  })();

  var RefRecordValueTwoObjectNames = Reftable.RefRecordValueTwoObjectNames = (function() {
    function RefRecordValueTwoObjectNames(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecordValueTwoObjectNames.prototype._read = function() {
      this.oid = this._io.readBytes(20);
      this.peeledOid = this._io.readBytes(20);
    }

    return RefRecordValueTwoObjectNames;
  })();

  var LogRecord = Reftable.LogRecord = (function() {
    function LogRecord(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    LogRecord.prototype._read = function() {
      this.logKeyPrefixLength = new Varint(this._io, this, null);
      this.logKeySuffixInfo = new Varint(this._io, this, null);
      this.logKeySuffix = this._io.readBytes(this.logKeySuffixLength);
      if (this.logValueType == 1) {
        this.logData = new LogData(this._io, this, this._root);
      }
    }
    Object.defineProperty(LogRecord.prototype, 'logKeySuffixLength', {
      get: function() {
        if (this._m_logKeySuffixLength !== undefined)
          return this._m_logKeySuffixLength;
        this._m_logKeySuffixLength = (this.logKeySuffixInfo.value >>> 3);
        return this._m_logKeySuffixLength;
      }
    });
    Object.defineProperty(LogRecord.prototype, 'logValueType', {
      get: function() {
        if (this._m_logValueType !== undefined)
          return this._m_logValueType;
        this._m_logValueType = (this.logKeySuffixInfo.value & 7);
        return this._m_logValueType;
      }
    });

    return LogRecord;
  })();

  var ObjectBlocks = Reftable.ObjectBlocks = (function() {
    function ObjectBlocks(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ObjectBlocks.prototype._read = function() {
      this._raw_records = [];
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this._raw_records.push(this._io.readBytes(this._root.footer.header.blockSize));
        var _io__raw_records = new KaitaiStream(this._raw_records[this._raw_records.length - 1]);
        this.records.push(new ObjectBlock(_io__raw_records, this, this._root));
        i++;
      }
    }
    Object.defineProperty(ObjectBlocks.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return ObjectBlocks;
  })();

  var IndexBlock = Reftable.IndexBlock = (function() {
    function IndexBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    IndexBlock.prototype._read = function() {
      this.indexBlockFlag = this._io.readU1();
      if (!(this.indexBlockFlag == 105)) {
        throw new KaitaiStream.ValidationNotEqualError(105, this.indexBlockFlag, this._io, "/types/index_block/seq/0");
      }
      this.indexBlockLen = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this._raw_indexRecords = this._io.readBytes((((this.indexBlockLen - this._io.pos) - (this.restartCount * 3)) - 2));
      var _io__raw_indexRecords = new KaitaiStream(this._raw_indexRecords);
      this.indexRecords = new IndexRecords(_io__raw_indexRecords, this, this._root);
      this.restartOffset = [];
      for (var i = 0; i < this.restartCount; i++) {
        this.restartOffset.push(this._io.readBitsIntBe(24));
      }
      this._io.alignToByte();
      this.iRestartCount = this._io.readU2be();
      this.blockPadding = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.blockPadding.push(this._io.readU1());
        i++;
      }
    }
    Object.defineProperty(IndexBlock.prototype, 'restartCount', {
      get: function() {
        if (this._m_restartCount !== undefined)
          return this._m_restartCount;
        var io = this._io;
        var _pos = io.pos;
        io.seek((this.indexBlockLen - 2));
        this._m_restartCount = io.readU2be();
        io.seek(_pos);
        return this._m_restartCount;
      }
    });

    return IndexBlock;
  })();

  var RefBlocks = Reftable.RefBlocks = (function() {
    function RefBlocks(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefBlocks.prototype._read = function() {
      this._raw_records = [];
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this._raw_records.push(this._io.readBytes(this._root.footer.header.blockSize));
        var _io__raw_records = new KaitaiStream(this._raw_records[this._raw_records.length - 1]);
        this.records.push(new RefBlock(_io__raw_records, this, this._root));
        i++;
      }
    }
    Object.defineProperty(RefBlocks.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return RefBlocks;
  })();

  var RefRecordValueDeletion = Reftable.RefRecordValueDeletion = (function() {
    function RefRecordValueDeletion(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecordValueDeletion.prototype._read = function() {
      this.noValue = this._io.readBytes(0);
    }

    return RefRecordValueDeletion;
  })();

  var LogBlocks = Reftable.LogBlocks = (function() {
    function LogBlocks(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    LogBlocks.prototype._read = function() {
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.records.push(new LogBlock(this._io, this, this._root));
        i++;
      }
    }
    Object.defineProperty(LogBlocks.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return LogBlocks;
  })();

  var LogBlock = Reftable.LogBlock = (function() {
    function LogBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    LogBlock.prototype._read = function() {
      this.logBlockFlag = this._io.readU1();
      if (!(this.logBlockFlag == 103)) {
        throw new KaitaiStream.ValidationNotEqualError(103, this.logBlockFlag, this._io, "/types/log_block/seq/0");
      }
      this.logBlockLen = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this._raw__raw_zlibDeflate = this._io.readBytes(0);
      var _process = new InflateZlib(this._io);
      this._raw_zlibDeflate = _process.decode(this._raw__raw_zlibDeflate);
      var _io__raw_zlibDeflate = new KaitaiStream(this._raw_zlibDeflate);
      this.zlibDeflate = new ZlibInflateLogBlock(_io__raw_zlibDeflate, this, this._root);
    }
    Object.defineProperty(LogBlock.prototype, 'data', {
      get: function() {
        if (this._m_data !== undefined)
          return this._m_data;
        this._m_data = this.logBlockLen;
        return this._m_data;
      }
    });

    return LogBlock;
  })();

  var ZlibInflateLogBlock = Reftable.ZlibInflateLogBlock = (function() {
    function ZlibInflateLogBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ZlibInflateLogBlock.prototype._read = function() {
      this._raw_logRecords = this._io.readBytes(((this._io.size - (this.restartCount * 3)) - 2));
      var _io__raw_logRecords = new KaitaiStream(this._raw_logRecords);
      this.logRecords = new LogRecords(_io__raw_logRecords, this, this._root);
      this.restartOffset = [];
      for (var i = 0; i < this.restartCount; i++) {
        this.restartOffset.push(this._io.readBitsIntBe(24));
      }
      this._io.alignToByte();
      this.iRestartCount = this._io.readU2be();
    }
    Object.defineProperty(ZlibInflateLogBlock.prototype, 'restartCount', {
      get: function() {
        if (this._m_restartCount !== undefined)
          return this._m_restartCount;
        var _pos = this._io.pos;
        this._io.seek((this._io.size - 2));
        this._m_restartCount = this._io.readU2be();
        this._io.seek(_pos);
        return this._m_restartCount;
      }
    });

    return ZlibInflateLogBlock;
  })();

  var LogRecords = Reftable.LogRecords = (function() {
    function LogRecords(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    LogRecords.prototype._read = function() {
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.records.push(new LogRecord(this._io, this, this._root));
        i++;
      }
    }
    Object.defineProperty(LogRecords.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return LogRecords;
  })();

  var RefBlock = Reftable.RefBlock = (function() {
    function RefBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefBlock.prototype._read = function() {
      this.refBlockFlag = this._io.readU1();
      if (!(this.refBlockFlag == 114)) {
        throw new KaitaiStream.ValidationNotEqualError(114, this.refBlockFlag, this._io, "/types/ref_block/seq/0");
      }
      this.refBlockLen = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this._raw_refRecords = this._io.readBytes((((this.refBlockLen - this._io.pos) - (this.restartCount * 3)) - 2));
      var _io__raw_refRecords = new KaitaiStream(this._raw_refRecords);
      this.refRecords = new RefRecords(_io__raw_refRecords, this, this._root);
      this.restartOffset = [];
      for (var i = 0; i < this.restartCount; i++) {
        this.restartOffset.push(this._io.readBitsIntBe(24));
      }
      this._io.alignToByte();
      this.iRestartCount = this._io.readU2be();
      if ( ((this._root.footer.refIndexPosition != 0) && (this._root.footer.header.blockSize != 0)) ) {
        this.blockPadding = [];
        for (var i = 0; i < (this._root.footer.header.blockSize - this.refBlockLen); i++) {
          this.blockPadding.push(this._io.readU1());
        }
      }
    }
    Object.defineProperty(RefBlock.prototype, 'restartCount', {
      get: function() {
        if (this._m_restartCount !== undefined)
          return this._m_restartCount;
        var io = this._io;
        var _pos = io.pos;
        io.seek((this.refBlockLen - 2));
        this._m_restartCount = io.readU2be();
        io.seek(_pos);
        return this._m_restartCount;
      }
    });

    return RefBlock;
  })();

  var Header = Reftable.Header = (function() {
    function Header(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    Header.prototype._read = function() {
      this.magic = this._io.readBytes(4);
      if (!((KaitaiStream.byteArrayCompare(this.magic, [82, 69, 70, 84]) == 0))) {
        throw new KaitaiStream.ValidationNotEqualError([82, 69, 70, 84], this.magic, this._io, "/types/header/seq/0");
      }
      this.version = this._io.readU1();
      this.blockSize = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this.minUpdateIndex = this._io.readU8be();
      this.maxUpdateIndex = this._io.readU8be();
    }

    return Header;
  })();

  var IndexRecords = Reftable.IndexRecords = (function() {
    function IndexRecords(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    IndexRecords.prototype._read = function() {
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.records.push(new IndexRecord(this._io, this, this._root));
        i++;
      }
    }
    Object.defineProperty(IndexRecords.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return IndexRecords;
  })();

  var RefRecordValueOneObjectName = Reftable.RefRecordValueOneObjectName = (function() {
    function RefRecordValueOneObjectName(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecordValueOneObjectName.prototype._read = function() {
      this.oid = this._io.readBytes(20);
    }

    return RefRecordValueOneObjectName;
  })();

  var ObjectBlock = Reftable.ObjectBlock = (function() {
    function ObjectBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ObjectBlock.prototype._read = function() {
      this.objectBlockFlag = this._io.readU1();
      if (!(this.objectBlockFlag == 111)) {
        throw new KaitaiStream.ValidationNotEqualError(111, this.objectBlockFlag, this._io, "/types/object_block/seq/0");
      }
      this.objectBlockLen = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this._raw_objectRecords = this._io.readBytes((((this.objectBlockLen - this._io.pos) - (this.restartCount * 3)) - 2));
      var _io__raw_objectRecords = new KaitaiStream(this._raw_objectRecords);
      this.objectRecords = new ObjectRecords(_io__raw_objectRecords, this, this._root);
      this.restartOffset = [];
      for (var i = 0; i < this.restartCount; i++) {
        this.restartOffset.push(this._io.readBitsIntBe(24));
      }
      this._io.alignToByte();
      this.iRestartCount = this._io.readU2be();
      if ( ((this._root.footer.objectIndexPosition != 0) && (this._root.footer.header.blockSize != 0)) ) {
        this.blockPadding = [];
        for (var i = 0; i < (this._root.footer.header.blockSize - this.objectBlockLen); i++) {
          this.blockPadding.push(this._io.readU1());
        }
      }
    }
    Object.defineProperty(ObjectBlock.prototype, 'restartCount', {
      get: function() {
        if (this._m_restartCount !== undefined)
          return this._m_restartCount;
        var io = this._io;
        var _pos = io.pos;
        io.seek((this.objectBlockLen - 2));
        this._m_restartCount = io.readU2be();
        io.seek(_pos);
        return this._m_restartCount;
      }
    });

    return ObjectBlock;
  })();

  var FirstRefBlock = Reftable.FirstRefBlock = (function() {
    function FirstRefBlock(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    FirstRefBlock.prototype._read = function() {
      this.header = new Header(this._io, this, this._root);
      this.refBlockFlag = this._io.readU1();
      if (!(this.refBlockFlag == 114)) {
        throw new KaitaiStream.ValidationNotEqualError(114, this.refBlockFlag, this._io, "/types/first_ref_block/seq/1");
      }
      this.refBlockLen = this._io.readBitsIntBe(24);
      this._io.alignToByte();
      this._raw_refRecords = this._io.readBytes((((this.refBlockLen - this._io.pos) - (this.restartCount * 3)) - 2));
      var _io__raw_refRecords = new KaitaiStream(this._raw_refRecords);
      this.refRecords = new RefRecords(_io__raw_refRecords, this, this._root);
      this.restartOffset = [];
      for (var i = 0; i < this.restartCount; i++) {
        this.restartOffset.push(this._io.readBitsIntBe(24));
      }
      this._io.alignToByte();
      this.iRestartCount = this._io.readU2be();
      if ( ((this._root.footer.refIndexPosition != 0) && (this._root.footer.header.blockSize != 0)) ) {
        this.blockPadding = [];
        for (var i = 0; i < (this._root.footer.header.blockSize - this.refBlockLen); i++) {
          this.blockPadding.push(this._io.readU1());
        }
      }
    }
    Object.defineProperty(FirstRefBlock.prototype, 'restartCount', {
      get: function() {
        if (this._m_restartCount !== undefined)
          return this._m_restartCount;
        var _pos = this._io.pos;
        this._io.seek((this.refBlockLen - 2));
        this._m_restartCount = this._io.readU2be();
        this._io.seek(_pos);
        return this._m_restartCount;
      }
    });

    return FirstRefBlock;
  })();

  var ObjectRecord = Reftable.ObjectRecord = (function() {
    function ObjectRecord(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    ObjectRecord.prototype._read = function() {
      this.objectPrefixLength = new Varint(this._io, this, null);
      this.objectSuffixInfo = new Varint(this._io, this, null);
      this.objectSuffix = KaitaiStream.bytesToStr(this._io.readBytes(this.objectSuffixLength), "ASCII");
      if (this.objectCnt3 == 0) {
        this.objectCntLarge = new Varint(this._io, this, null);
      }
      if (this.objectPositionCount > 0) {
        this.positionDelta = [];
        for (var i = 0; i < this.objectPositionCount; i++) {
          this.positionDelta.push(new Varint(this._io, this, null));
        }
      }
    }
    Object.defineProperty(ObjectRecord.prototype, 'objectSuffixLength', {
      get: function() {
        if (this._m_objectSuffixLength !== undefined)
          return this._m_objectSuffixLength;
        this._m_objectSuffixLength = (this.objectSuffixInfo.value >>> 3);
        return this._m_objectSuffixLength;
      }
    });
    Object.defineProperty(ObjectRecord.prototype, 'objectCnt3', {
      get: function() {
        if (this._m_objectCnt3 !== undefined)
          return this._m_objectCnt3;
        this._m_objectCnt3 = (this.objectSuffixInfo.value & 7);
        return this._m_objectCnt3;
      }
    });
    Object.defineProperty(ObjectRecord.prototype, 'objectPositionCount', {
      get: function() {
        if (this._m_objectPositionCount !== undefined)
          return this._m_objectPositionCount;
        this._m_objectPositionCount = (this.objectCnt3 == 0 ? this.objectCntLarge.value : this.objectCnt3);
        return this._m_objectPositionCount;
      }
    });

    return ObjectRecord;
  })();

  var Footer = Reftable.Footer = (function() {
    function Footer(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    Footer.prototype._read = function() {
      this.header = new Header(this._io, this, this._root);
      this.refIndexPosition = this._io.readU8be();
      this.objectInfo = this._io.readU8be();
      this.objectIndexPosition = this._io.readU8be();
      this.logPosition = this._io.readU8be();
      this.logIndexPosition = this._io.readU8be();
      this.crc32 = this._io.readU4be();
    }
    Object.defineProperty(Footer.prototype, 'totalSizeRef', {
      get: function() {
        if (this._m_totalSizeRef !== undefined)
          return this._m_totalSizeRef;
        this._m_totalSizeRef = (this.refIndexPosition > 0 ? this.refIndexPosition : (this.objectPosition > 0 ? this.objectPosition : (this.logPosition > 0 ? this.logPosition : (this._io.size - 68))));
        return this._m_totalSizeRef;
      }
    });
    Object.defineProperty(Footer.prototype, 'objectIdLen', {
      get: function() {
        if (this._m_objectIdLen !== undefined)
          return this._m_objectIdLen;
        this._m_objectIdLen = (this.objectInfo & 31);
        return this._m_objectIdLen;
      }
    });
    Object.defineProperty(Footer.prototype, 'totalSizeLogIndex', {
      get: function() {
        if (this._m_totalSizeLogIndex !== undefined)
          return this._m_totalSizeLogIndex;
        this._m_totalSizeLogIndex = (this.logIndexPosition == 0 ? 0 : ((this._io.size - 68) - this.logIndexPosition));
        return this._m_totalSizeLogIndex;
      }
    });
    Object.defineProperty(Footer.prototype, 'totalSizeLog', {
      get: function() {
        if (this._m_totalSizeLog !== undefined)
          return this._m_totalSizeLog;
        this._m_totalSizeLog = (this.logPosition == 0 ? 0 : ((this.logIndexPosition > 0 ? this.logIndexPosition : (this._io.size - 68)) - this.logPosition));
        return this._m_totalSizeLog;
      }
    });
    Object.defineProperty(Footer.prototype, 'totalSizeObjectIndex', {
      get: function() {
        if (this._m_totalSizeObjectIndex !== undefined)
          return this._m_totalSizeObjectIndex;
        this._m_totalSizeObjectIndex = (this.objectIndexPosition == 0 ? 0 : ((this.logPosition > 0 ? this.logPosition : (this._io.size - 68)) - this.objectIndexPosition));
        return this._m_totalSizeObjectIndex;
      }
    });
    Object.defineProperty(Footer.prototype, 'totalSizeRefIndex', {
      get: function() {
        if (this._m_totalSizeRefIndex !== undefined)
          return this._m_totalSizeRefIndex;
        this._m_totalSizeRefIndex = (this.refIndexPosition == 0 ? 0 : ((this.objectPosition > 0 ? this.objectPosition : (this.logPosition > 0 ? this.logPosition : (this._io.size - 68))) - this.refIndexPosition));
        return this._m_totalSizeRefIndex;
      }
    });
    Object.defineProperty(Footer.prototype, 'objectPosition', {
      get: function() {
        if (this._m_objectPosition !== undefined)
          return this._m_objectPosition;
        this._m_objectPosition = (this.objectInfo >>> 5);
        return this._m_objectPosition;
      }
    });
    Object.defineProperty(Footer.prototype, 'totalSizeObject', {
      get: function() {
        if (this._m_totalSizeObject !== undefined)
          return this._m_totalSizeObject;
        this._m_totalSizeObject = (this.objectPosition == 0 ? 0 : ((this.objectIndexPosition > 0 ? this.objectIndexPosition : (this.logPosition > 0 ? this.logPosition : (this._io.size - 68))) - this.objectPosition));
        return this._m_totalSizeObject;
      }
    });

    return Footer;
  })();

  var RefRecords = Reftable.RefRecords = (function() {
    function RefRecords(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    RefRecords.prototype._read = function() {
      this.records = [];
      var i = 0;
      while (!this._io.isEof()) {
        this.records.push(new RefRecord(this._io, this, this._root));
        i++;
      }
    }
    Object.defineProperty(RefRecords.prototype, 'totalCount', {
      get: function() {
        if (this._m_totalCount !== undefined)
          return this._m_totalCount;
        this._m_totalCount = this.records.length;
        return this._m_totalCount;
      }
    });

    return RefRecords;
  })();
  Object.defineProperty(Reftable.prototype, 'footer', {
    get: function() {
      if (this._m_footer !== undefined)
        return this._m_footer;
      var _pos = this._io.pos;
      this._io.seek((this._io.size - 68));
      this._m_footer = new Footer(this._io, this, this._root);
      this._io.seek(_pos);
      return this._m_footer;
    }
  });

  return Reftable;
})();
return Reftable;
}));
